package cn.doitedu.ml.demos;

import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

public class Image2VectorText {
    public static void main(String[] args) throws Exception {

        // 样本输出
        // String imagePath = "userprofile/data/knndemo/sample_vec_text/sampl.txt";
        String imagePath = "userprofile/data/knndemo/test_vec_text/sampl.txt";
        BufferedWriter bw = new BufferedWriter(new FileWriter(imagePath));

        //String textPath = "userprofile/data/knndemo/samples";
        String textPath = "userprofile/data/knndemo/test";

        File sampDir = new File(textPath);
        File[] sampleFiles = sampDir.listFiles();

        for (File sampleFile : sampleFiles) {
            BufferedImage bufferedImage = ImageIO.read(sampleFile);
            String label = sampleFile.getName().split("_")[1];
            bw.write(label+",");
            for(int i=0;i<32;i++){
                for (int j=0;j<32;j++){
                    bw.write((bufferedImage.getRGB(j,i)==-1?"0":"1")+",");
                }
            }

            bw.newLine();
        }

        bw.close();
    }
}
